function application(){
	var _self = this;
	
	this.config = {
		api: '4DD845D1BB619BEEFB641EC49A7D8735',
		searchval: '请输入您要搜索的关键词',
		reg: {
			phone: /((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/,
			email: /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/
		}
	}
	
	// 首页图片展示触发标题
	$('#icase, #ipro, .product-lister').on('mouseenter', '.item', function(){
		$(this).find('.shadow').stop(true, true).animate({'bottom': 0}, 300, 'easeOutCubic');
	})
	$('#icase, #ipro, .product-lister').on('mouseleave', '.item', function(){
		$(this).find('.shadow').stop(true, true).animate({'bottom': -100}, 300, 'easeOutCubic');
	})
	
	// 导航置顶
	$(window).bind('scroll', function(){
		var _stp = $(document).scrollTop(),
			_hei = $(window).height();
		
		if($('#location').length){
			if(_stp > 90){
				$('#location').addClass('fixed');
			}else{
				$('#location').removeClass('fixed');
			}
		}else{
			if(_stp > 0){
				$('#header').addClass('fixed');
			}else{
				$('#header').removeClass('fixed');
			}
		}
		
		if(_stp > _hei){
			$('#itop').fadeIn();
		}else{
			$('#itop').fadeOut();
		}
		
	})
	
    // 显示留言表单
    $('#showMsg').bind('click', function(){
        if($('#contactMsg').is(':hidden')){
          	$('#contactMsg').show().addClass('animated fadeInLeft');
        }else{
            $('#contactMsg').removeClass('fadeInLeft').addClass('fadeOutLeft');
            setTimeout(function(){
				$('#contactMsg').hide().removeClass('fadeOutLeft animated');
            }, 1000)
       }
    })
	
    // 
    $('#showSos').bind('click', function(){
        if($('#searcher').is(':hidden')){
			$('#searcher').slideDown();
            $('#ordered').removeClass('bounceInRight').addClass('bounceOutRight');
            setTimeout(function(){
				$('#ordered').hide();
            }, 500)
        }else{
        	$('#searcher').slideUp();
            $('#ordered').show().removeClass('bounceOutRight').addClass('bounceInRight');
        }
    })
    
    // 
    $('#menu li').hover(
        function(){
			$(this).addClass('active');
            if($(this).find('dd').length > 0){
				$(this).children('.drop').show();
            }
        },
        function(){
			$(this).removeClass('active');
            $(this).children('.drop').hide();
        }
    )
    
	this.init();
}
application.prototype = {
	init: function(){
		var _self = this;
		
		// API验证
		if(typeof(_self.config.api) == 'undefined' || _self.config.api.substr(13,4) != 'BEEF'){
			return false;
		}
		
		// 格式化电话号码
		$('[ig-phone]').each(function(index, element){
			var tel400 = $.trim($(this).text()), telLength = tel400.length;
			if(telLength == 11){  // 手机号码 OR 座机号码
				var firstNum = tel400.substr(0,1);
				if(firstNum == 0){
					var tel1 = tel400.substr(0, 4);
					var tel2 = tel400.substr(4, 7);
					tel400 = tel1+ "-" + tel2;
				}else{
					var tel1 = tel400.substr(0, 3);
					var tel2 = tel400.substr(3, 4);
					var tel3 = tel400.substr(7, 4);
					tel400 = tel1+ "-" + tel2 + "-" + tel3;
				}
			}else if(telLength == 12){
				var tel1 = tel400.substr(0, 4);
				var tel2 = tel400.substr(4, 8);
				tel400 = tel1+ "-" + tel2;
			}else if(telLength == 10){
				var tel1 = tel400.substr(0, 3);
				var tel2 = tel400.substr(3, 4);
				var tel3 = tel400.substr(7, 3);
				tel400 = tel1+ "-" + tel2 + "-" + tel3;
			}
			$(this).html(tel400);
		})
		
		// 加入收藏
		$('#addFavo').bind('click', function(){
			app.addFavorite($('title').html(), location.href, '');
		});
		
		// 设为首页
		$('#setHome').bind('click', function(){
			app.SetHome(this, location.href);
		});
		
		// 返回顶部
		$('#itop').bind('click', function(){
			$('body, html').animate({'scrollTop': 0}, 200);
		})
		
		_self.scroller();
		_self.searcher();
		_self.plugs();
		_self.former();
		_self.bdmap();
        _self.ajaxLoad()
	},
	scroller: function(){
		// 首页banner
		if($('#banner .list li').length > 1){
			!function(){
				var $id = $('#banner'),
					$list = $id.children('.list'),
					$tip = $id.children('.tip'),
					$prev = $id.children('.prev'),
					$next = $id.children('.next'),
					t,
					_interval = 8000,
					_speed = 1000,
					_index = 0,
					_size = $list.children('*').length;
				
				if($tip.length){
					var _html = '';
					for(var i=0; i<_size; i++){
						if(i==0){
							_html += '<li class="current"></li>';
						}else{
							_html += '<li></li>';
						}
					}
					$tip.html(_html);
				}
				
				$list.children('*').eq(0).addClass('active');
				
				function _prev(){
					if(_index < 0){
						_index = _size - 1;
					}
					$list.children('*').eq(_index).addClass('active').stop(true, true).fadeIn(_speed).siblings('*').removeClass('active').stop(false, false).fadeOut(_speed);
					$tip.children('*').eq(_index).addClass('current').siblings().removeClass('current');
				}
				
				function _next(){
					if(_index >= _size){
						_index = 0;
					}
					$list.children('*').eq(_index).addClass('active').stop(true, true).fadeIn(_speed).siblings('*').removeClass('active').stop(false, false).fadeOut(_speed);
					$tip.children('*').eq(_index).addClass('current').siblings().removeClass('current');
				}
				
				$tip.children('*').click(function(){
					_index = $(this).index();
					_next();
				})
				
				$prev.bind('click', function(){
					_index --;
					_prev();
				})
				
				$next.bind('click', function(){
					_index ++;
					_next();
				})
				
				$id.hover(
					function(){
						clearInterval(t);
					},
					function(){
						t = setInterval(function(){
							_index ++;
							_next();
						}, _interval);
					}
				)
				
				t = setInterval(function(){
					_index ++;
					_next();
				}, _interval);
			}()
		}
        
		// 广告位Advantage
		if($('#advantage .list li').length > 1){
			!function(){
				var $id = $('#advantage'),
					$list = $id.children('.list'),
					$tip = $id.children('.tip'),
					$prev = $id.children('.prev'),
					$next = $id.children('.next'),
					t,
					_width = $id.width(),
					_interval = 5000,
					_speed = 1000,
					_index = 0,
					_size = $list.children('*').length;
				
				$list.append($list.html())
					 .width(2*_width*_size)
					 .children('*').width(_width);
				
				if($tip.length){
					var _html = '';
					for(var i=0; i<_size; i++){
						if(i==0){
							_html += '<li class="current"></li>';
						}else{
							_html += '<li></li>';
						}
					}
					$tip.html(_html);
				}
				
				function _resize(){
					$list.width(2*_width*_size)
					     .css({'left': - _width*_index})
					     .children('*').width(_width);
					
					t = setInterval(function(){
						_index ++;
						_next();
					}, _interval);
				}
				
				function _prev(){
					if(_index < 0){
						$list.css({'left': -(_size) * _width});
						_index = _size - 1;
					}
					$list.stop(true, true).animate({'left': -_index * _width}, _speed, 'easeOutCirc');
					$tip.children('*').eq(_index).addClass('current').siblings().removeClass('current');
				}
				
				function _next(){
					if(_index >= _size){
						$list.css({'left': 0});
						_index = 1;
					}
					$list.stop(true, true).animate({'left': -_index * _width}, _speed, 'easeOutCirc');
					$tip.children('*').eq(_index).addClass('current').siblings().removeClass('current');
				}
				
				$tip.children('*').click(function(){
					_index = $(this).index();
					_next();
				})
				
				$prev.bind('click', function(){
					_index --;
					_prev();
				})
				
				$next.bind('click', function(){
					_index ++;
					_next();
				})
				
				$id.hover(
					function(){
						clearInterval(t);
					},
					function(){
						t = setInterval(function(){
							_index ++;
							_next();
						}, _interval);
					}
				)
				
				$(window).bind('resize', function(){
					_width = $id.width();
					clearInterval(t);
					_resize();
				})
				
				t = setInterval(function(){
					_index ++;
					_next();
				}, _interval);
			}()
		}
		
		// 作品展示
		if($('#ipro .list li').length > 4){
			!function(){
				var $id = $('#ipro'),
					$list = $id.find('.list'),
					$tip = $id.find('.tip'),
					$prev = $id.find('.prev'),
					$next = $id.find('.next'),
					t,
					_width = $id.find('.main').width()*.25,
					_interval = 7000,
					_speed = 1000,
					_index = 0,
					_size = $list.children('*').length;
				
				$list.append($list.html())
					 .width(2*_width*_size)
					 .children('*').width(_width);
				
				if($tip.length){
					var _html = '';
					for(var i=0; i<_size; i++){
						if(i==0){
							_html += '<li class="current"></li>';
						}else{
							_html += '<li></li>';
						}
					}
					$tip.html(_html);
				}
				
				function _resize(){
					$list.width(2*_width*_size)
					     .css({'left': - _width*_index})
					     .children('*').width(_width);
					
					t = setInterval(function(){
						_index ++;
						_next();
					}, _interval);
				}
				
				function _prev(){
					if(_index < 0){
						$list.css({'left': -(_size) * _width});
						_index = _size - 1;
					}
					$list.stop(false, false).animate({'left': -_index * _width}, _speed, 'easeInOutExpo');
					$tip.children('*').eq(_index).addClass('current').siblings().removeClass('current');
				}
				
				function _next(){
					if(_index > _size){
						$list.css({'left': 0});
						_index = 1;
					}
					$list.stop(false, false).animate({'left': -_index * _width}, _speed, 'easeInOutExpo');
					$tip.children('*').eq(_index).addClass('current').siblings().removeClass('current');
				}
				
				$tip.children('*').click(function(){
					_index = $(this).index();
					_next();
				})
				
				$prev.bind('click', function(){
					_index --;
					_prev();
				})
				
				$next.bind('click', function(){
					_index ++;
					_next();
				})
				
				$id.hover(
					function(){
						clearInterval(t);
					},
					function(){
						t = setInterval(function(){
							_index ++;
							_next();
						}, _interval);
					}
				)
				
				$(window).bind('resize', function(){
					_width = $id.find('.main').width()*.25;
					clearInterval(t);
					_resize();
				})
				
				t = setInterval(function(){
					_index ++;
					_next();
				}, _interval);
			}()
		}
	},
	plugs: function(){
		// 百度分享-浮窗+图标
		window._bd_share_config={
			"common": {
				"bdSnsKey":{},
				"bdText":"",
				"bdMini":"2",
				"bdMiniList":false,
				"bdPic":"",
				"bdStyle":"0",
				"bdSize":"24"
			},
			"slide": {
				"type":"slide",
				"bdImg":"3",
				"bdPos":"left",
				"bdTop":"160.5"
			},
			"share": {}
		};
		with(document)0[(getElementsByTagName('head')[0]||body)
			.appendChild(createElement('script'))
			.src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
		
		// 
	},
    bdmap: function(){
        var func = function(){
        	if($(".BMap_bubble_title a").length < 1){
                setTimeout(func, 100);
              }else{
                $(".BMap_bubble_title a").attr({"target":"_blank"});
              }
            }
        func();  // 执行函数
        
    },
	former: function(){
        var _self =this;
		$postform = $('#formPost');
		$postform.find('.txt, .text, .code').bind({
			'focus': function(){
				$(this).parent().addClass('onfocus');
				if ($(this).val() == $(this).attr('placeholder')) {
					$(this).val('');
				}
			},
			'blur': function(){
				$(this).parent().removeClass('onfocus');
				$('#jLog').hide();
				if ($(this).val() == '') {
					$(this).val($(this).attr('placeholder'));
				}
			},
			'keyup': function(){
				$('#jLog').hide();
			}
		});
		$postform.find('[type="submit"]').bind('click', function () {
			var $name = $postform.find('[name="Name"]'),
				$phone = $postform.find('[name="Phone"]'),
				$email = $postform.find('[name="Email"]'),
				$code = $postform.find('[name="txtImageCode"]');
			
			// 姓名
			if ($name.val() == '' || $name.val() == $name.attr('placeholder')) {
				app.jLog($name.attr('null'), $name.offset().left, $name.offset().top);
				$name.focus();
				return false;
			}
			// 联系方式
			if ($phone.val() == '' || $phone.val() == $phone.attr('placeholder')) {
				app.jLog($phone.attr('null'), $phone.offset().left, $phone.offset().top);
				$phone.focus();
				return false;
			}
			if (!$phone.val().match(_self.config.reg.phone)) {
				app.jLog($phone.attr('error'), $phone.offset().left, $phone.offset().top);
				$phone.focus();
				return false;
			}
			// 电子邮箱
			if (($email.val() != '' || $email.val() != $email.attr('placeholder')) && !$email.val().match(_self.config.reg.email)) {
				// app.jLog($email.attr('error'), $email.offset().left, $email.offset().top);
				// $email.focus();
				// return false;
			}
			// 验证码
			if ($code.val() == '' || $code.val() == $code.attr('placeholder')) {
				app.jLog($code.attr('null'), $code.offset().left, $code.offset().top);
				$code.focus();
				return false;
			}
		})
	},
	searcher: function(){
		var _self = this,
			isFocus = false;
        $('#SearchTxt').bind({
            'focus': function(){
                
            },
            'blur': function(){
                
            }
        })
		$('#SearchTxt').bind({
			'focus': function(){
				isFocus = true;
				$(this).val('');
			},
			'blur': function(){
				isFocus = false;
                if($(this).val() == ''){
					$(this).val(_self.config.searchval);
                }
			}
		})
		$('#SearchSubmit').bind('click', function(){
			if($('#SearchTxt').val() == '' || $('#SearchTxt').val() == $('#SearchTxt').attr('placeholder')){
				alert(_self.config.searchval);
				return false;
			}
			search();
		});
		$(document).keydown(function(event){
			event = event ? event : ( window.event ? window.event : null );
			if(event.keyCode == 13 && isFocus == true){
				$('#SearchSubmit').trigger('click');
			}
		});
	},
    ajaxLoad: function(){        
        var self = this, bool = true, pageNum = '', nodata="";
		if(!$('#ajaxLoader').length || !$('.pager').length){ return false; }
		
        if($('.pager a:contains("后一页")').attr('href') != "#" && $('.pager a:contains("后一页")').length){ 
			$('#ajaxPager').show(); 
		}else{
			$('#ajaxPager').hide();
		}
        
        $('#ajaxPager').bind('click', function(){
            bool = false;
			var p = $('.pager a:contains("后一页")'),
				url = p.attr('href');
				// console.log(!$('.pager a:contains("后一页")').length);
            if(pageNum == url || $('.pager a:contains("后一页")').attr('href') == "#" || !$('.pager a:contains("后一页")').length ){
                if(nodata == ''){
                    $('#ajaxPager').hide();
                }else{
                	$('#ajaxPager').html(nodata);
                }
                return false;
            }else{
                pageNum = url
            }
            $.ajax({
                url : url,
                type: 'GET',
                dataType: 'html',
                beforeSend: function(){
                    $('#ajaxPager').html('正在努力加载..');
                },
                success: function(data){
                  var html = $(data).find('#ajaxLoader .list').html(),
					  pager = $(data).find('.pager  a:contains("后一页")').attr('href');
				  $('#ajaxLoader .list').append(html);
                  if(pager == undefined || pager == "#"){
                      nodata == '' ? $('#ajaxPager').hide() : $('#ajaxPager').html(nodata) ;
                  }else{
                      p.attr({'href': pager});
                      $('#ajaxPager').html('点击加载更多');
                  }
                  bool = true;
                }
            });
        });
    },
    addFavorite: function(title, url){
        try{
            window.external.addFavorite(url, title);
        }
        catch(e){
            try{
                window.sidebar.addPanel(title, url, '');
            }
            catch(e){
                alert('抱歉，您所使用的浏览器无法完成此操作');
           }
        }
    },
	SetHome: function(obj,url){
		try{
			obj.style.behavior='url(#default#homepage)';
			obj.setHomePage(url);
	    }catch(e){
		   if(window.netscape){
			  try{
				  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			  }catch(e){
				  alert("抱歉，此操作被浏览器拒绝！\n\n请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为'true'");
			  }
		   }else{
		       alert("抱歉，您所使用的浏览器无法完成此操作。\n\n您需要手动将"+url+"设置为首页。");
		   }
	    }
	},
	jAlert: function(info, title, callback){
		var _self = this,
			_html = '';
		
		if(typeof(title) == 'function'){
			callback = title;
			title = '温馨提示';
		}else if(title == null){
			title = '温馨提示';
		}
		
		_self.layout(1);
		
		_html += '<div class="dialog-alert" id="jAlear">';
		_html += '<div class="head">';
		_html += '<h2>'+ title +'</h2>';
		_html += '<a href="javascript:;" class="close"></a>';
		_html += '</div>';
		_html += '<div class="main">';
		_html += '<p>'+ info +'</p>';
		_html += '</div>';
		_html += '<div class="foot">';
		_html += '<a href="javascript:;" class="ok">我知道了</a>';
		_html += '</div>';
		_html += '</div>';		
				
		var $obj = $(_html);
		$obj.appendTo('body').show();
		$obj.find('.close')
			.bind('click', function(){
				_self.layout(0);
				$obj.hide().remove();
				if(callback){
					callback(false);
				}
			});
		$obj.find('.ok')
			.bind('click', function(){
				_self.layout(0);
				$obj.hide().remove();
				if(callback){
					callback(true);
				}
			})
	},
	jConfirm: function(info, title, callback){
		var _self = this,
			_html = '';
		
		if(typeof(title) == 'function'){
			callback = title;
			title = '温馨提示';
		}else if(title == null){
			title = '温馨提示';
		}
		
		_self.layout(1);		
		
		_html += '<div class="dialog-confirm" id="jConfirm">';
		_html += '<div class="head">';
		_html += '<h2>'+ title +'</h2>';
		_html += '<a href="javascript:;" class="close"></a>';
		_html += '</div>';
		_html += '<div class="main">';
		_html += '<p>'+ info +'</p>';
		_html += '</div>';
		_html += '<div class="foot">';
		_html += '<a href="javascript:;" class="ok">确定</a>';
		_html += '<a href="javascript:;" class="cancel">取消</a>';
		_html += '</div>';
		_html += '</div>';		
				
		var $obj = $(_html);
		$obj.appendTo('body').show();
		$obj.find('.close')
			.bind('click', function(){
				_self.layout(0);
				$obj.hide().remove();
				if(callback){
					callback(false);
				}
			});
		$obj.find('.ok')
			.bind('click', function(){
				_self.layout(0);
				$obj.hide().remove();
				if(callback){
					callback(true);
				}
			})
		$obj.find('.cancel')
			.bind('click', function(){
				_self.layout(0);
				$obj.hide().remove();
				if(callback){
					callback(false);
				}
			})
	},
	jLog: function(i, l, t){
		var _offsetX = 0,
			_offsetY = 44;
		if(i == null){
			i = '必填字段，请输入正确的内容';
		}
        if ($('#jLog').length) {
            $('#jLog').html(i + '<i></i>').show().css({ 'left': (l + _offsetX), 'top': (t + _offsetY) });
        } else {
            $('<div class="dialog-log" id="jLog">' + i + '<i></i></div>').appendTo('body').css({ 'left': (l + _offsetX), 'top': (t + _offsetY) });
        }
    },
	layout: function(u){
		if(u == 0){
			$('#dialogLayout').remove();
		}else{
			if(!$('#dialogLayout').length){
				$('<div class="dialog-layout" id="dialogLayout"></div>').appendTo('body').show();
			}
		}
	}
}
var app = new application();